package com.shxy.service.impl;

import com.shxy.dao.insurance.AccountDao;
import com.shxy.dao.insurance.CustomerDao;
import com.shxy.dao.insurance.InsuranceCaseDao;
import com.shxy.entity.insurance.Account;
import com.shxy.entity.insurance.Customer;
import com.shxy.entity.insurance.InsuranceCase;
import com.shxy.service.ICustomerService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;

import java.time.Instant;
import java.util.List;

/**
 * 客户信息管理实现类
 */
@Service
public class CustomerService implements ICustomerService {

//    @Autowired
//    private CustomerDao customerDao;
//    @Autowired
//    private AccountDao accountDao;
//    @Autowired
//    private InsuranceCaseDao insuranceCaseDao;
//
//    @Override
//    public List<Customer> getCustomerAll() {
//        return customerDao.findAllByIsActive(true);
//    }
//
//    @Override
//    public List<String> getCompanies() {
//        return customerDao.getCompanies();
//    }
//
//    @Override
//    public List<Account> getCustomerAccounts(int customerId) {
//        return accountDao.findAccountsByCustomerId(customerId);
//    }
//
//    @Override
//    public boolean accountExists(int customerId, String bank, String account) {
//        return accountDao.existsByAccount(account);
//    }
//
//    @Override
//    public Account saveAccount(int customerId, String bank, String account, String phone) {
//        Customer customer = new Customer();
//        customer.setId(customerId);
//        Account acc = new Account();
//        acc.setBank(bank);
//        acc.setAccount(account);
//        acc.setCustomer(customer);
//        acc.setPhone(phone);
//        return accountDao.save(acc);
//    }
//
//    @Override
//    public InsuranceCase addInsuranceCase(CaseUpload caseInfo) {
//        InsuranceCase insuranceCase = new InsuranceCase();
//        BeanUtils.copyProperties(caseInfo, insuranceCase);
//        // 住院
//        if(caseInfo.getItype() == 1){
//            insuranceCase.setHospitalIn(caseInfo.getHospitalStay()[0]);
//            insuranceCase.setHospitalOut(caseInfo.getHospitalStay()[1]);
//        }
//        else {
//            insuranceCase.setBillingDate(caseInfo.getBillingDate());
//        }
//        Account account = accountDao.getById(caseInfo.getAccountId());
//        insuranceCase.setAccount(account);
//        insuranceCase.setCustomer(account.getCustomer());
//        insuranceCase.setReportDate(Instant.now().toEpochMilli());
//        return insuranceCaseDao.save(insuranceCase);
//    }
//
//    @Override
//    public List<InsuranceCase> getInsuranceCaseList(int customerId, long dateStart, long dateEnd, int pageIndex, int pageSize) {
//        PageRequest pr = PageRequest.of(pageIndex, pageSize);
//        // 查询指定客户指定时间段的案件列表
//        if(customerId > 0 && dateStart != 0 && dateEnd != 0){
//            return insuranceCaseDao.findAllByCustomerIdAndReportDateBetween(customerId, dateStart, dateEnd, pr).toList();
//        }
//        // 查询所有客户指定时间段的案件列表
//        else if(dateStart != 0 && dateEnd != 0){
//            return insuranceCaseDao.findAllByReportDateBetween(dateStart, dateEnd,
//                    pr).toList();
//        }
//        // 查询全部案件列表
//        else {
//            return insuranceCaseDao.findAll(pr).toList();
//        }
//    }
//
//    @Override
//    public boolean deleteCustomerById(int id) {
//        Customer customer = customerDao.findById(id);
//        if(customer == null){
//            return false;
//        }
//        customer.setIsActive(false);
//        customerDao.save(customer);
//        return true;
//    }
//
//    @Override
//    public Customer saveCustomer(CustomerUpload customerUpload) {
//        // 获取客户对象
//        Customer customer = customerUpload.getStype() == 0 ? new Customer() : customerDao.findById(customerUpload.getId());
//
//        // 如果获取客户对象成功
//        if(customer != null){
//            BeanUtils.copyProperties(customerUpload, customer);
//            customerDao.save(customer);
//        }
//        return customer;
//    }
}
